package com.example.demo.api.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.demo.api.EmailMessageService;
import com.example.demo.dao.EmailMessageDao;
import com.example.demo.entity.EmailMessage;
import com.example.demo.vo.EmailMessageVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Hy on 2018/8/3.
 */
@Service
public class EmailMessageServiceImpl implements EmailMessageService{

    @Autowired
    private EmailMessageDao emailMessageDao;
    @Override
    public List<EmailMessageVo> scanForSending() {
        List<EmailMessage> emailMessages = emailMessageDao.findEmailMsgByStatus();
        List<EmailMessageVo> vos =new ArrayList<>();
        for (EmailMessage msg:emailMessages
             ) {
            EmailMessageVo vo =new EmailMessageVo();
            BeanUtils.copyProperties(msg,vo);
            vos.add(vo);
        }
        return vos;
    }

    @Override
    public int sendSuccessfully(Long userId) {
        Integer result = emailMessageDao.updateStatusById(userId);
        return result;
    }
}
